<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ include file="/pages/login/common.jsp"%>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="B2B电商平台" name="description" />
<meta content="B2B电商平台" name="keyword" />

<title>B2B电商平台.商品分类设置</title>
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/css/style.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/css/btn.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/proManage.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/css/themes.css" />
<link rel="stylesheet"
	href="<%=path%>/include/JQuery zTree v3.4/css/demo.css">
<link rel="stylesheet"
	href="<%=path%>/include/JQuery zTree v3.4/css/zTreeStyle/zTreeStyle.css">
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/css/register_icss.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/sweetalert/sweetalert.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/css/page.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/pagination/page.css" media="all">
<link rel="stylesheet" type="text/css"
	href="<%=path %>/include/css/mmt_trading.css" />

<script type="text/javascript"
	src="<%=path %>/include/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript"
	src="<%=path %>/include/js/icss.shop.manage.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/cookies.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/pagination/jquery.pagination.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/pagination/init.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/JQuery zTree v3.4/js/jquery.ztree.core-3.4.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/JQuery zTree v3.4/js/jquery.ztree.excheck-3.4.js"></script>
<script type="text/javascript"
	src="<%=path %>/include/js/icss.common.js"></script>
<script type="text/javascript"
	src="<%=path %>/include/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript"
	src="<%=path %>/include/sweetalert/sweetalert-dev.js"></script>

<style type="text/css">
.trBgd  th {
	border-right: 1px solid #ddd;
	line-height: 30px;
	font-size: 12px;
}

em.create {
	background-position: -50px -44px;
	line-height: 28px;
	display: inline-block;
	font-style: normal;
	background-repeat: no-repeat;
	text-indent: 15px;
	float: right;
	cursor: pointer;
}

.create {
	background: url("<%=path%>/images/coupons/sort_zss.png");
}

#tbody a {
	color: blue;
}

#tbody td {
	border-bottom: 1px solid #ddd;
	border-right: 1px solid #ddd;
	padding: 4px;
}

#treeDemo {
	width: 95%;
}


<%-- #addPro button{
    width:44px;
    height:24px;
    line-height:24px;   
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: 0 -203px;
    border:0;
    cursor:pointer;
    font: 12px/1.5 arial,tahoma,\5b8b\4f53;
    margin: 0 0 0 5px;
    outline:none;
    background-image: url('<%=path%>/include/css/img/xs_bgx.png');  


} --%>
#tbody a:hover {
	background-color: white;
	color: red;
}
#nandb th{
    border:1px #ddd solid;   
 }
button{
	background-image: url("<%=path%>/include/css/img/xs_bgx.png");
    background-color: transparent;
}
</style>
<script type="text/javascript">
	$(function(){		
		zTree = $.fn.zTree.init($("#treeDemo"), treeSetting);
		$("#tbody").html("<td colspan='7' style='text-align:center;line-height:40px;border: 1px solid #ddd;' >请选择类别</>");	    
	});
	var pagination;
	function _queryList(){
		
		var url = "<%=path %>/productForManager/queryProductForManagerList.do";
		var data = {
			productTypeCode : $("#productTypeCode").val()
		};
		
		
		pagination = _initPagination({'pageId':'pagination','url': url,'data': data, 'rows': 10, 'callback':_initDataList});
	}
	
	function _initDataList(data) {
		
 		var d = data.rows;
		var str = "";
		for(var i=0;i<d.length;i++){
			str += '<tr class="list_table_tr" style="border: 1px solid #ddd;">';
			str += '	<td  nowrap style="height:40px;text-align: left;border-left: 1px solid #ddd; ">&nbsp;' + d[i].PRODUCT_NAME + '</td>';
			str += '	<td  nowrap >';
			//str += '    	<div>';
			str += "        		<img src='"+d[i].PRODUCT_PIC+"' style='vertical-align:middle;' width='50' height='43.5' alt='' onerror='javascript:this.src=\"<%=path%>/download/error/nopicture.jpg\"' resizeimg='true'>";
			//str += ' 		</div>';//图片
			str +='</td>';
			if(d[i].UP_STATUS==1){
				str += '	<td  nowrap >上架</td>';
			}else{
				str += '	<td  nowrap >下架</td>';
			}
			
			if(d[i].UP_STATUS==1){
				str += '	<td  style="text-align:center;" nowrap>';
				str += 			d[i].UP_TIME;
				str += '	</td>';
			}else{
				str += '	<td  style="text-align:center;" nowrap>';
				str += 			d[i].DOWN_TIME;
				str += '	</td>';
			}
			str += '	<td  nowrap  style="text-align: right;">' + d[i].PRODUCT_SCORE + '&nbsp;</td>';
			str += '	<td  nowrap  style="text-align: right;">' + d[i].PRODUCT_SUM_SCORE_AMOUNT + '&nbsp;</td>';	
			str += '	<td  nowrap  >';
			str += "<a href=\"javascript:onclick=_deleteProduct('"+d[i].UUID+"')\" class='del'>删除</a>";
			str +='     </td>';
			str += '</tr>';
		}
		//alert(str);
		$("#tbody").html(str);
		
		if(d.length==0){	
			$("#tbody").html("<td colspan='8' style='text-align:center;line-height:40px;border-left: 1px solid #ddd;' >没有该分类的商品数据</>");
		}
		_reHeight();
		
	 }
	var params = function(args) {
		var p = [];
		for(var n in args)
			p.push(n + '=' + args[n]);
		return encodeURI('?' + p.join('&'));
	};
	
   function _addProduct(){
		if($("#productTypeCode").val()!=""){
			var tId=$("#productTypeCode").val();
			var data = {tId:tId,bId:$("#productTypeId").val()};
			location.href = '<%=path%>/pages/productForManager/categoryProductList.jsp' + params(data);
		}else{
			parent.swal("请选择一个子类");
		}
		
	}
	
	function _deleteProduct(uuid){
		parent.swal({
			title: "删除", 
			text: "确认是否删除吗？", 
			type: "warning",
			showCancelButton: true,
			closeOnConfirm: false,
			cancelButtonText: "取消",
			confirmButtonText: "删除",
			confirmButtonColor: "#ec6c62"
			}, function() {
				parent.swal.close();
				$.ajax({
					type:"post",
					url: "<%=path%>/productForManager/deleteProductForManager.do",
					data:{uuid:uuid},
					dataType:"json",
					success:function(data){
						if(data.success){
							parent.swal("",data.msg,"success");
							_queryList();
						}
					}
				});
		});
		
	}

	
	
</script>
</head>
<body style="font-family: '微软雅黑';">

	<input type="hidden" id="productTypeCode" name="productTypeCode"
		value="">
	<input type="hidden" id="productTypeId" name="productTypeId" value="">
	<div id="contentDiv" style="padding:4px; width:99%;">
		<div class="colnums-2-ab-b">
			<div class="toptil" >分类商品</div>
			<div style="width:20%; float: left;">
				<div style="height:400px;width:100%;overflow-x: hidden;">
					<ul id="treeDemo" class="ztree"
						style="margin-top:0;background-color:#fff;border:1px #ccc solid;width:93%;overflow:auto;"></ul>
				</div>
			</div>
			<div class="row-fluid dataTables_wrapper" 
				style="width:79%;float: left;margin-left: 5px;border: 0px solid #e0e0e0;">
				<table
					class="table table-hover table-nomargin table-bordered usertable dataTable"
					style="width: 100%; border-spacing: 0;margin-right: 10px;">
					<thead>
						<tr id="nandb" style="height: 35px;line-height: 35px;">
							<th colspan="3" style="text-align: left;border-right:none;padding-left: 2px;"><span
								id="productCategoryName"
								style="font-weight: bold;font-size: 17px;"></span></th>
							<th id="addPro" colspan="4" style="text-align: right;border-left:none;padding: 5px 4px;">
							     <!-- <button
									type="button" id="addProBtn" onclick="_addProduct()"
									style="margin-bottom: 3px;">添加商品</button> -->
								 <button  type="button" class="cxx_btn" onclick="_addProduct()">添加</button>
						</th>

						</tr>
						<tr class="trBgd"
							style="background-color: #eee;text-align: center; height: 31px; border: 1px solid #ddd; white-space: nowrap; background-position: 0 -123px; line-height: 30px; font-weight: bold;">
							<th style="border-left:1px #ddd solid; ">商品名称</th>
							<th>图片</th>
							<th>上架/下架</th>
							<th>上架/下架时间</th>
							<th>商品评分</th>
							<th>商品评分次数</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="tbody" style="font-size: 13px">
					</tbody>
				</table>
				<div id="pagination"></div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
  	$(document).ready(function(){
		_reHeight();
	});
	function _reHeight(){
		var main = $(window.parent.document).find("#rightFrame");
		var mainheight = $("#contentDiv").height();
		main.height(mainheight);
	}
  	var zTree = null;
	/* 
	 * 下拉树的设置 
	 */  
	var treeSetting = {  
	    view: {  
	        dblClickExpand: false  
	    },  
		data: {  
			simpleData: {  
			    enable: true,
			    rootPId: 0
			}  
		},
		async:{
			enable: true,//设置ztree是否开启异步加载模式
			showLine: true ,//设置是否显示连接线
			type: "post",//post方式请求数据
			url: getUrl,//数据请求url
			autoParam:["id","name"],//异步加载时需要自动提交父节点属性的参数
			otherParam:{"otherParam":"zTreeAsyncTest"},
			dataFilter: filter
		},
		callback: {
			onClick: onClick,//点击节点
			onAsyncError : zTreeOnAsyncError,//加载失败
			onAsyncSuccess: zTreeOnAsyncSuccess//加载完成
		}
	}; 
	
	function getUrl(treeId, treeNode){		
		var url = "<%=path%>/productForManager/getTree.do";
		return url;
	}

	/* 
	 * 点击事件 
	 */
	function onClick(e, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		nodes = zTree.getSelectedNodes();
		treeNode = nodes[0];
		if (treeNode.isParent) {//判断是否是父节点
			$("#productTypeCode").val("");
			$("#productCategoryName").text("");
			$("#tbody")
					.html(
							"<td colspan='8' style='text-align:center;line-height:40px;border-left: 1px #ddd solid;' >请选择子类</>");

		} else {
			$("#productTypeId").val(treeNode.tId);
			$("#productTypeCode").val(treeNode.id);
			$("#productCategoryName").text("" + treeNode.name);
			_queryList();
		}

	}

	//过滤函数  
	function filter(treeId, parentNode, childNodes) {
		if (!childNodes)
			return null;
		for (var i = 0, l = childNodes.length; i < l; i++) {
			//childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');  
		}
		return childNodes;
	}
	//加载完成
	var firstAsyncSuccessFlag = 0;
	var s = 0;
	function zTreeOnAsyncSuccess(event, treeId, msg) {
		var argsFromPageA = args();
		if (firstAsyncSuccessFlag == 0) {

			
			if (argsFromPageA.tId == undefined) {
				if (firstAsyncSuccessFlag < 2) {

					var nodes = zTree.getNodes();
					zTree.expandNode(nodes[0], true);

				}
			} else {

				for (var i = 1; i < argsFromPageA.tId.length / 3; i++) {
					var treenode = zTree.getNodeByParam("id", argsFromPageA.tId
							.substring(0, 3 * i), null);
					zTree.expandNode(treenode, true);
				}
				
				
				
				//var treenode1 = zTree.getNodeByParam("id", argsFromPageA.tId, null);

				//alert(argsFromPageA.tId.length);
				//debugger;
				//zTree.selectNode(treenode1);
			}
			//debugger;
			//firstAsyncSuccessFlag++;
		}
		firstAsyncSuccessFlag++;
        if(argsFromPageA.tId != undefined){
        	var m="#"+argsFromPageA.bId+"_a";
			//debugger;
			$(m).click();
        	/* $("#"+argsFromPageA.bId+"_a").click(); */
        }
		/* if (firstAsyncSuccessFlag == 2) {
			$("#treeDemo_3_a").click();
		} */

	};

	function SelectNode() {
		var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		var treenode = treeObj.getNodeByParam("id", 002004, null);
		treeObj.expandNode(treenode, true, true, true);
		debugger;
		treeObj.selectNode(treenode);
	}
	//加载失败提示  
	function zTreeOnAsyncError(event, treeId, treeNode, XMLHttpRequest,
			textStatus, errorThrown) {
		alert("加载错误：" + XMLHttpRequest);
	};
	var args = function(params) {
		var a = {};
		params = params || location.search;
		if (!params)
			return {};
		params = decodeURI(params);
		params.replace(/(?:^\?|&)([^=&]+)(?:\=)([^=&]+)(?=&|$)/g, function(m,
				k, v) {
			a[k] = v;
		});
		return a;
	};
</script>
</html>
